 package org.edu.modules.portal.service.impl;

 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import java.util.List;
 import org.edu.modules.portal.entity.VeSiteCategory;
 import org.edu.modules.portal.mapper.VeSiteCategoryMapper;
 import org.edu.modules.portal.service.IVeSiteCategoryService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;




 @Service
 public class VeSiteCategoryServiceImpl
   extends ServiceImpl<VeSiteCategoryMapper, VeSiteCategory>
   implements IVeSiteCategoryService
 {
   @Autowired
   private VeSiteCategoryMapper veSiteCategoryMapper;

   public JSONArray queryTree(Wrapper<VeSiteCategory> queryWrapper, Integer pid) {
     JSONObject json = new JSONObject();
/* 27 */     List<VeSiteCategory> list = this.veSiteCategoryMapper.selectList(queryWrapper);
/* 28 */     if (pid == null) {
       pid = Integer.valueOf(0);
     }
/* 31 */     JSONArray jArray = getChildren(list, pid);
/* 32 */     return jArray;
   }


   private JSONArray getChildren(List<VeSiteCategory> list, Integer pid) {
     JSONArray jArray = new JSONArray();
/* 38 */     for (int i = 0; i < list.size(); i++) {
/* 39 */       if (((VeSiteCategory)list.get(i)).getPid().equals(pid)) {
/* 40 */         JSONObject jObj = new JSONObject(true);
         jObj.put("id", ((VeSiteCategory)list.get(i)).getId());
/* 42 */         jObj.put("title", ((VeSiteCategory)list.get(i)).getTitle());
/* 43 */         jObj.put("coverId", ((VeSiteCategory)list.get(i)).getCoverid());
/* 44 */         jObj.put("type", ((VeSiteCategory)list.get(i)).getType());
         jObj.put("typeName", showTypeName(((VeSiteCategory)list.get(i)).getType()));
/* 46 */         jObj.put("listSort", ((VeSiteCategory)list.get(i)).getListsort());
/* 47 */         jObj.put("status", ((VeSiteCategory)list.get(i)).getStatus());
/* 48 */         jObj.put("pid", ((VeSiteCategory)list.get(i)).getPid());
         JSONArray jArrayChild = getChildren(list, ((VeSiteCategory)list.get(i)).getId());
/* 50 */         if (jArrayChild.size() > 0) {
/* 51 */           jObj.put("children", jArrayChild);
         }
         jArray.add(jObj);
/* 54 */         list.remove(i);
/* 55 */         i--;
       }
     }
/* 58 */     return jArray;
   }
   private String showTypeName(String typeId) {
     String typeName = "";
/* 62 */     switch (typeId) {
       case "Node":
/* 64 */         typeName = "默认模块";
         break;
       case "News":
/* 67 */         typeName = "信息模型";
         break;
       case "Picture":
/* 70 */         typeName = "图片模型";
         break;
       case "Link":
         typeName = "外部链接";
         break;
       case "Book":
/* 76 */         typeName = "在线留言";
         break;
       case "Abutment":
/* 79 */         typeName = "需求对接";
         break;
     }
/* 82 */     return typeName;
   }
 }



